#include <QtCore>
#include "SmtpMime"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    SmtpClient smtp("smtp.qq.com", 25, SmtpClient::TcpConnection);

    smtp.setUser("2478080620@qq.com"); //qq网页版邮箱的设置页面，开启pop3/smtp服务
    //smtp.setPassword("oieyxjglzhpcdixf");
    smtp.setPassword("XXXXXXXXXXXXXXXX"); //腾讯邮箱的授权码，不是邮箱密码

    MimeMessage message;

    EmailAddress sender("2478080620@qq.com");
    message.setSender(&sender);

    EmailAddress to("mozhidong@126.com");
    message.addRecipient(&to);

    message.setSubject("SmtpClient for Qt by tcp");

    // Now add some text to the email.
    // First we create a MimeText object.
    MimeText text;
    text.setText("Hi,\nThis is a simple email message.\n");
    message.addPart(&text);

    if (!smtp.connectToHost()) {
        qDebug() << "Failed to connect to host!" << endl;
        return -1;
    }

    if (!smtp.login()) {
        qDebug() << "Failed to login!" << endl;
        return -2;
    }

    if (!smtp.sendMail(message)) {
        qDebug() << "Failed to send mail!" << endl;
        return -3;
    }

    smtp.quit();
}

